Skip to content

build: Update NET Framework target to 4.8 #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

DennisDyallo
Copy link
Collaborator

@DennisDyallo DennisDyallo commented Jul 1, 2025

This pull request updates the project to target .NET Framework 4.8 instead of 4.7 and upgrades several dependencies to their latest versions. It includes changes to project files, source code, and build configurations to reflect this update.

Updating addresses performance, greater API and Netstandard 2.0 support, as well as upgrades addresses vulnerabilities (CVE-2019-0981: Denial of Service in System.Private.Uri)

These are in place upgrades that most machines should have by now.

NET 472 is included on Windows Server 2019 (WS2019 is EOL by Msft) and most users will have it installed already.
NET 48 is included in Server 2022, and is supported by and Windows Server 2008 R2 and upwards. Most users should have it already.

Based on researching the compatibility of different .NET targetFramework versions and Windows and Windows server, I recommend upgrading to net48 to enable the performance improvements, vulnerability patches and API features. This version allows us to upgrade and ensures the broadest compatibility.

image

Below are the changes for each of these version updates:


.NET Framework 4.7.1

  • BCL: Full netstandard2.0 support, ResourceManager race condition fix, improved Parallel.For reliability.
  • Security: SHA-2 support for Forms Authentication.
  • General: Numerous bug fixes and performance improvements.

Full changelog


.NET Framework 4.7.2

  • ASP.NET: Various bug fixes and performance improvements.
  • BCL: Cryptography, collections, and serialization improvements.
  • General: Included with Windows Server 2019.

Full changelog


.NET Framework 4.8

BCL & CLR:

  • zlib updated to 1.2.11.
  • DateTime/DateTimeOffset leap second handling.
  • Reduced memory allocations in cryptography.
  • New API for certificate thumbprints.
  • Improved GC, JIT, and threading performance.
  • AppDomain and process shutdown reliability improvements.

Full changelog


Framework Upgrade and Code Adjustments:

  • Updated TargetFrameworks in Yubico.Core.csproj and Yubico.YubiKey.csproj to replace net47 with net48. [1] [2]
  • Adjusted comments and preprocessor directives in source files to reference .NET 4.8 instead of .NET 4.7. [1] [2] [3]

Dependency Upgrades:

  • Upgraded package references in Yubico.Core.csproj and Yubico.YubiKey.csproj to newer versions, including Microsoft.Extensions.Configuration.Json, Microsoft.Extensions.Logging.Abstractions, and System.Formats.Cbor. [1] [2] [3]

Build and Library Updates:

  • Renamed Libraries.Net47.cs to Libraries.Net48.cs and updated corresponding implementation references to align with the new framework version.
  • Added .NETFramework4.8 support in Yubico.NativeShims.nuspec, including new build and library files for net48. [1] [2]

@DennisDyallo DennisDyallo requested a review from Copilot July 1, 2025 11:02
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the project to target .NET Framework 4.8 instead of 4.7 while also upgrading several dependencies to their latest versions. Key changes include the update of TargetFrameworks in both project files, adjustments to comments and preprocessor directives to reflect .NET 4.8, and modifications in the nuspec file to include .NETFramework4.8 support.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Yubico.YubiKey/src/Yubico.YubiKey.csproj Updated target framework and upgraded dependency package versions.
Yubico.NativeShims/Yubico.NativeShims.nuspec Added .NETFramework4.8 group and file entries; still retains .NETFramework4.7 group.
Yubico.Core/src/Yubico/PlatformInterop/Libraries.cs Updated comments and preprocessor directives to use net48.
Yubico.Core/src/Yubico/PlatformInterop/Libraries.Net48.cs Replaced framework-specific references from NET47 to NET48.
Yubico.Core/src/Yubico/Core/Devices/Hid/WindowsHidDevice.cs Updated comment reference to reflect net48 support.
Yubico.Core/src/Yubico.Core.csproj Updated TargetFrameworks and dependency versions to 9.0.6.
Comments suppressed due to low confidence (1)

Yubico.NativeShims/Yubico.NativeShims.nuspec:15

  • The nuspec still includes a target group for .NETFramework4.7; consider removing this if the project is now fully updated to .NET Framework 4.8.
            <group targetFramework=".NETFramework4.7" />

Microsoft.Extensions.Configuration.Json
Microsoft.Extensions.Logging.Abstractions
Microsoft.Extensions.Logging.Console
Microsoft.Extensions.Options.ConfigurationExtensions
@DennisDyallo DennisDyallo added enhancement New feature or request dependencies Pull requests that update a dependency file labels Jul 1, 2025
@DennisDyallo DennisDyallo self-assigned this Jul 1, 2025
Copy link

github-actions bot commented Jul 1, 2025

Test Results: Windows

    2 files      2 suites   10s ⏱️
3 905 tests 3 905 ✅ 0 💤 0 ❌
3 907 runs  3 907 ✅ 0 💤 0 ❌

Results for commit c1a04fd.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 1, 2025

Test Results: Ubuntu

    2 files      2 suites   16s ⏱️
3 897 tests 3 897 ✅ 0 💤 0 ❌
3 899 runs  3 899 ✅ 0 💤 0 ❌

Results for commit c1a04fd.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jul 1, 2025

Test Results: MacOS

    2 files      2 suites   9s ⏱️
3 897 tests 3 897 ✅ 0 💤 0 ❌
3 899 runs  3 899 ✅ 0 💤 0 ❌

Results for commit c1a04fd.

♻️ This comment has been updated with latest results.

@DennisDyallo DennisDyallo added the build Pull requests that update the build label Jul 1, 2025
@AlexandreEXFO
Copy link
Contributor

@DennisDyallo : Don't forget to update the README.md.

image

@AlexandreEXFO
Copy link
Contributor

Updating the framework also allows AesGcmPrimitivesOpenSsl class (Yubico.NET.SDK/Yubico.Core/src/Yubico/Core/Cryptography/AesGcmPrimitivesOpenSsl.cs) to be replaced with this one in order to use the native implementation in .NET.

// Copyright 2025 Yubico AB
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Security.Cryptography;

namespace Yubico.Core.Cryptography
{
    /// <summary>
    /// An .NET implementation of the IAesGcmPrimitives interface, exposing
    /// AES-GCM primitives to the SDK.
    /// </summary>
    public class AesGcmPrimitivesNet : IAesGcmPrimitives
    {
        private const int NonceLength = 12;
        private const int AuthTagLength = 16;

        /// <inheritdoc />
        public void EncryptAndAuthenticate(
            ReadOnlySpan<byte> keyData,
            ReadOnlySpan<byte> nonce,
            ReadOnlySpan<byte> plaintext,
            Span<byte> ciphertext,
            Span<byte> tag,
            ReadOnlySpan<byte> associatedData)
        {
            if (nonce.Length != NonceLength || ciphertext.Length != plaintext.Length
                || tag.Length != AuthTagLength)
            {
                throw new ArgumentException(ExceptionMessages.InvalidAesGcmInput);
            }

            if (keyData.Length != 16 && keyData.Length != 24 && keyData.Length != 32)
            {
                throw new ArgumentException("Invalid key length.");
            }

            using var aesGcm = new AesGcm(keyData);
            aesGcm.Encrypt(nonce, plaintext, ciphertext, tag, associatedData);
        }

        /// <inheritdoc />
        public bool DecryptAndVerify(
            ReadOnlySpan<byte> keyData,
            ReadOnlySpan<byte> nonce,
            ReadOnlySpan<byte> ciphertext,
            ReadOnlySpan<byte> tag,
            Span<byte> plaintext,
            ReadOnlySpan<byte> associatedData)
        {

            if (nonce.Length != NonceLength || ciphertext.Length != plaintext.Length
                || tag.Length != AuthTagLength)
            {
                throw new ArgumentException(ExceptionMessages.InvalidAesGcmInput);
            }

            if (keyData.Length != 16 && keyData.Length != 24 && keyData.Length != 32)
            {
                throw new ArgumentException("Invalid key length.");
            }

            try
            {
                using var aesGcm = new AesGcm(keyData);
                aesGcm.Decrypt(nonce, ciphertext, tag, plaintext, associatedData);
                return true;
            }
            catch (CryptographicException)
            {
                return false;
            }
        }
    }
}

Copy link

github-actions bot commented Jul 4, 2025

Code Coverage

Package Line Rate Branch Rate Complexity Health
Yubico.Core 40% 31% 4371
Yubico.YubiKey 51% 46% 20712
Summary 49% (35550 / 72561) 44% (8706 / 19851) 25083

Minimum allowed line rate is 40%

@DennisDyallo
Copy link
Collaborator Author

Thanks @AlexandreEXFO
We believe opting to go for the NET 472 (#274) framework instead. The NET472 has the broadest support and adoption, so we believe this is a good middle way. Even though the case for NET48 is a good one, we prefer minimal risk for now.
This way will address the CVE as well as the other features of NET472.

Keen to hear your thoughts.
All the best

@AlexandreEXFO
Copy link
Contributor

@DennisDyallo: On our side, we use .NET Core. The goal was mainly to remove the vulnerability for this framework so I am very comfortable with the proposed change.

@DennisDyallo
Copy link
Collaborator Author

DennisDyallo commented Jul 4, 2025

Thank you for bringing it to our attention. Always happy to hear from our users. We have a Discussions up as well for two way communication about the direction of the SDK. Feel feel to look around at some point. It's new and doesn't have much yet though :) @AlexandreEXFO

@DennisDyallo DennisDyallo deleted the dennisdyallo/net48 branch July 7, 2025 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Pull requests that update the build dependencies Pull requests that update a dependency file enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants